package com.example.drzhang.oengldemo.data;

import android.opengl.GLES20;

import com.example.drzhang.oengldemo.render.ColorShaderProgram;

/**
 * Created by drzhang on 2018/1/10.
 */

public class Mallet {

    private static final int POSITION_COMPONENT_COUNT = 2;
    private static final int COLOR_COMPONENT_COUNT = 3;
    private static final int STRIDE = (POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) * Constant.BYTES_PER_FLOAT;

    private static final float[] VERTEX_DATA = new float[]{
            // x,     y,    R,  G   B
            0f,    -0.40f, 0f, 0f, 1.0f,
            0f,     0.40f, 1f, 1f,   0f
    };

    private VertexArray mVertexArray;

    public Mallet() {
        mVertexArray = new VertexArray(VERTEX_DATA);
    }

    public void bindData(ColorShaderProgram program){
        mVertexArray.setVertexAttribPointer(
                0,
                program.getPositionAttributeLocation(),
                POSITION_COMPONENT_COUNT,
                STRIDE
        );
        mVertexArray.setVertexAttribPointer(
                POSITION_COMPONENT_COUNT,
                program.getColorAttributeLocation(),
                COLOR_COMPONENT_COUNT,
                STRIDE
        );
    }

    public void draw(){
        GLES20.glDrawArrays(GLES20.GL_POINTS,0, 2);
    }
}
